import type { TablePaginationConfig } from 'ant-design-vue'
import type { MaybeRef } from 'vue'
export interface TablePaginationOptions {
  current?: number
  pageSize?: number
  total?: MaybeRef<number>
  onChange?: (current: number, pageSize: number) => void
}
export function useTablePagination(options: TablePaginationOptions) {
  const current = computed(() => options?.current || 1)
  const pageSize = computed(() => options?.pageSize || 10)
  const total = computed(() => options?.total ?? 0)
  const pagination = reactive<TablePaginationConfig>({
    current: unref(current),
    pageSize: unref(pageSize),
    total: unref(total) as number,
    showSizeChanger: true,
    showQuickJumper: true,
    showTotal: total => `总共：${total} 条`,
    onChange: (current, pageSize) => {
      pagination.current = current
      pagination.pageSize = pageSize
      options?.onChange?.(current, pageSize)
    },
  })
  return pagination
}
